import os
from . import git_op

"""
默往App代码同步
"""

def Get_All_Items():
    items = [
        {
            "remote_url": "git@192.168.199.85:ios/project/mostone/Application.git",
            "item_name": "Application",
        },
        {
            "remote_url": "git@192.168.199.85:ios/project/mostone/MOPrefix.git",
            "item_name": "MOPrefix"
        },
        {
            "remote_url": "git@192.168.199.85:ios/project/mostone/MOPublic.git",
            "item_name": "MOPublic"
        },
        {
            "remote_url": "git@192.168.199.85:ios/project/mostone/MOIM.git",
            "item_name": "MOIM"
        },
        {
            "remote_url": "git@192.168.199.85:ios/project/mostone/MOIMPublic.git",
            "item_name": "MOIMPublic"
        },
        {
            "remote_url": "git@192.168.199.85:ios/project/mostone/MOLogin.git",
            "item_name": "MOLogin"
        },
        {
            "remote_url": "git@192.168.199.85:ios/project/mostone/MOLoginPublic.git",
            "item_name": "MOLoginPublic"
        },
        {
            "remote_url": "git@192.168.199.85:ios/project/mostone/MOMoment.git",
            "item_name": "MOMoment"
        },
        {
            "remote_url": "git@192.168.199.85:ios/project/mostone/MOMomentPublic.git",
            "item_name": "MOMomentPublic"
        },
        {
            "remote_url": "git@192.168.199.85:ios/project/mostone/MOAlbumModule.git",
            "item_name": "MOAlbumModule"
        },
        {
            "remote_url": "git@192.168.199.85:ios/project/mostone/MOAlbumPublic.git",
            "item_name": "MOAlbumPublic"
        },
        {
            "remote_url": "git@192.168.199.85:ios/project/mostone/MOPocket.git",
            "item_name": "MOPocket"
        },
        {
            "remote_url": "git@192.168.199.85:ios/project/mostone/MOPocketPublic.git",
            "item_name": "MOPocketPublic"
        },
        {
            "remote_url": "git@192.168.199.85:ios/project/mostone/MOExplorePublic.git",
            "item_name": "MOExplorePublic"
        },
        {
            "remote_url": "git@192.168.199.85:ios/project/mostone/MOExplore.git",
            "item_name": "MOExplore"
        },
        {
            "remote_url": "git@192.168.199.85:ios/project/mostone/MOShareModule.git",
            "item_name": "MOShareModule"
        },
        {
            "remote_url": "git@192.168.199.85:ios/project/mostone/MOSharePublic.git",
            "item_name": "MOSharePublic"
        },
        {
            "remote_url": "git@192.168.199.85:ios/project/mostone/MOAnalyticsModule.git",
            "item_name": "MOAnalyticsModule"
        },
        {
            "remote_url": "git@192.168.199.85:ios/project/mostone/MOMineModule.git",
            "item_name": "MOMineModule"
        },
        {
            "remote_url": "git@192.168.199.85:ios/project/mostone/MOMinePublic.git",
            "item_name": "MOMinePublic"
        },
        {
            "remote_url": "git@192.168.199.85:ios/project/mostone/MOCollectModule.git",
            "item_name": "MOCollectModule"
        },
        {
            "remote_url": "git@192.168.199.85:ios/project/mostone/MOCollectPublic.git",
            "item_name": "MOCollectPublic"
        },
        {
            "remote_url": "git@192.168.199.85:ios/project/mostone/MOSettingModule.git",
            "item_name": "MOSettingModule"
        },
        {
            "remote_url": "git@192.168.199.85:ios/project/mostone/MOSettingPublic.git",
            "item_name": "MOSettingPublic"
        },
        {
            "remote_url": "git@192.168.199.85:ios/project/mostone/MOPersonalInfomationModule.git",
            "item_name": "MOPersonalInfomationModule"
        },
        {
            "remote_url": "git@192.168.199.85:ios/project/mostone/MOPersonalInfomationPublic.git",
            "item_name": "MOPersonalInfomationPublic"
        }
    ]

    return items

def sync_code(git_path, branch="dev"):
    for item in Get_All_Items():
        if item['item_name'] == 'Application':
            branch = 'dev-back'
        else:
            branch = 'dev'
        item_path = git_path + "/" + item["item_name"]
        if os.path.exists(item_path):
            git_op.excute_shell('git reset --hard', path=item_path)
            # got pull
            print("exist item: ", item["item_name"])
            git_op.git_pull(git_path=item_path)
        else:
            # git clone
            print("not exist item: ", item["item_name"])
            git_op.git_clone(git_path=git_path, branch=branch, remote_url=item["remote_url"], item_name=item["item_name"])


if __name__ == "__main__":    
    git_path = "/Users/mac/Desktop/GitProjectPackage/Mostone/Project/MostOne"
    
    sync_code(git_path)
    
    pass